using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DM.DAO;
using DM.Entity;

namespace DM.Web.Admin
{
    public partial class TimKiemAdmin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindingGridView();
            }
        }

        protected string GetImage(string id)
        {
            HinhDAO _hinhDAO = new HinhDAO();
            TinTucDAO _tinTucDao = new TinTucDAO();
            TinTuc tin = _tinTucDao.Get(Common.ParseInt32(id));
            Hinh hinh = _hinhDAO.Get(tin);
            return hinh.Hinhurl;
        }

        protected void BindingGridView()
        {
            string keyWord = Request.QueryString["key"];
            TinTucDAO _tinTucDao = new TinTucDAO();
            DataTable tableTinTuc = _tinTucDao.Search(keyWord);
            gvSearch.DataSource = tableTinTuc;
            gvSearch.DataBind();
        }

        /// <summary>
        /// Property Column nào shorting trong GridViewTinTuc
        /// </summary>
        private string ShortColumn
        {
            get
            {
                object o = ViewState["ShortColumn"];
                if (o == null) return "NgayDang";
                return (string)o;
            }
            set { ViewState["ShortColumn"] = value; }
        }
        /// <summary>
        /// Property Short theo hướng nào (Ascend hay Descend)
        /// </summary>
        private bool ShortAscend
        {
            get
            {
                object o = ViewState["ShortAscend"];
                if (o == null) return false;
                return (bool)o;
            }
            set { ViewState["ShortAscend"] = value; }
        }

        protected void gvSearch_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (e.SortExpression == ShortColumn) ShortAscend = !ShortAscend;
            else
            {
                ShortColumn = e.SortExpression;
                ShortAscend = true;
            }
            BindingGridView();
        }

        protected void gvSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSearch.PageIndex = e.NewPageIndex;
            BindingGridView();
        }
    }
}
